﻿using System.Collections.Generic;
using System.Data;
using Ue.Infrastructure;
using Ue.Infrastructure.RepositoryFramework.Repository;
using Ue.Qcdz.Domain.SinglePages;

namespace Ue.Qcdz.Repositories.SinglePages
{
    public class SinglePageRepository : SqlServerRepository<SinglePage>, ISinglePageRepository
    {
        public SinglePageRepository()
            : this(null) { }

        public SinglePageRepository(IUnitOfWork uniteOfWork)
            : base(uniteOfWork) { }

        protected override System.Data.IDataParameter[] BuildParameters(SinglePage entity)
        {

            return new IDataParameter[]{
              this.RepositoryDriver.BuildParameter(SinglePageFactory.FieldNames.EntityKey,entity.Key),
              this.RepositoryDriver.BuildParameter(SinglePageFactory.FieldNames.Title,entity.Title??""),              
              this.RepositoryDriver.BuildParameter(SinglePageFactory.FieldNames.Content,entity.Content??""),   
              this.RepositoryDriver.BuildParameter(SinglePageFactory.FieldNames.ImageUrl,entity.ImageUrl??""), 
              this.RepositoryDriver.BuildParameter(SinglePageFactory.FieldNames.Status,entity.Status),              
              this.RepositoryDriver.BuildParameter(SinglePageFactory.FieldNames.CategoryId,entity.CategoryId??""),   
              this.RepositoryDriver.BuildParameter(SinglePageFactory.FieldNames.DisplayOrder,entity.DisplayOrder),
              this.RepositoryDriver.BuildParameter(SinglePageFactory.FieldNames.CreateOn,entity.CreateOn)
  
            };
        }

        protected override IWhereClause BuildWhereClauseBy(Infrastructure.DomainBase.IDataQuery dataQuery)
        {
            if (dataQuery is ISinglePageDataQuery)
            {
                return new SinglePageDataQueryWhereClause(dataQuery as ISinglePageDataQuery);
            }

            return null;
        }

        protected override string[] GetBaseInsertFields()
        {
            return new string[] {
                    SinglePageFactory.FieldNames.EntityKey,
                    SinglePageFactory.FieldNames.Title,
                    SinglePageFactory.FieldNames.Content, 
                   SinglePageFactory.FieldNames.ImageUrl, 
                   SinglePageFactory.FieldNames.CategoryId,
                   SinglePageFactory.FieldNames.Status, 
                   SinglePageFactory.FieldNames.DisplayOrder,
                    SinglePageFactory.FieldNames.CreateOn     
            };
        }

        protected override string[] GetBaseUpdateFields()
        {
            return new string[] {
                    SinglePageFactory.FieldNames.Title,
                    SinglePageFactory.FieldNames.Content, 
                    SinglePageFactory.FieldNames.ImageUrl, 
                    SinglePageFactory.FieldNames.CategoryId,
                    SinglePageFactory.FieldNames.Status, 
                    SinglePageFactory.FieldNames.DisplayOrder  
            };
        }

        protected override IDictionary<string, SqlServerRepositoryBase<SinglePage>.ChildDataHandler> GetBuildEntityChildCallbacks()
        {
            return null;
        }

        protected override string GetDataTableName()
        {
            return "SinglePages";
        }
        protected override string GetKeyFieldName()
        {
            return "id";
        }
        protected override string GetOrderBy()
        {
            return "DisplayOrder DESC";
        }
    }
}
